<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-04-12 18:47:17
 * @LastEditTime: 2024-05-22 12:47:15
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 新建 / 编辑 页面
 * @FilePath: \vue-code-design\templates\vue3ElementPlus\DrawerDemo\views\{{{=it.newOptions.MODULE_VALUE}}}\components\Drawer\create.vue
 * Copyright 版权声明
-->
<template>
  <div class="">
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-width="80px"
      style='width:100%;'
    >
      {{{~it.newOptions.column :value:index}}}
      <el-form-item label="{{{=value.label || ""}}}" prop="{{{=value.prop || ""}}}">
        <el-input v-model="temp.{{{=value.prop || ""}}}" placeholder="请输入{{{=value.label || ""}}}"></el-input>
      </el-form-item>
      {{{~}}}
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Create',
  computed: {
    ...mapGetters([
      'drawerCurrent'
    ]),
    drawerType: function() {
      return this.drawerCurrent.drawerType
    }
  },
  components: {
  },
  data() {
    return {
      temp: {
      },
      rules: {
        {{{~it.newOptions.column :value:index}}}{{{=value.prop || ""}}}: [
          { required: true, message: '请输入{{{=value.label || ""}}}', trigger: 'change' }
        ]{{{? (index + 1) !== it.newOptions.columnNum}}},{{{?}}}
        {{{~}}}
      }
    }
  },
  watch: {
    // 表单内容体
    temp: {
      handler: function(val, oldVal) {
      },
      deep: true
    }
  },
  created() {
    // console.log('-----------', this.drawerCurrent)
    // 列表传过来的数据
    const temp = this.drawerCurrent.params.row
    this.temp = Object.assign({}, this.temp, temp)
    // *******************如果是 【编辑】 需要从接口数据的话执行一下操作
    if (this.drawerType === 'UPDATE') {
      // drawer loadding 状态 打开
      this.$store.dispatch('SetDrawerloading', true)
      setTimeout(() => {
        // drawer loadding 状态 关闭
        this.$store.dispatch('SetDrawerloading', false)
      }, 500)
    }
  },
  mounted() {

  },
  methods: {
    // 富文本编辑器内容改变
    handleEditorChange(params) {
      console.log('富文本内容改变：', params)
      const html = params.html
      this.temp.desc = html
    },
    // 提交表单
    submitForm() {
      return this.$refs['dataForm'].validate()
    },
    // 获取表单数据
    getFormData() {
      return this.temp
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
